package demo.game.chess.client.ui;

import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.user.client.ui.ListBox;

public class PlayWithComputerChessUI extends AbstractChessUI {

	ListBox computerLevels = new ListBox();

	ComputerPlayMoveListener computerPlayer = new ComputerPlayMoveListener();

	public PlayWithComputerChessUI() {
		super(ComputerPlayMoveListener.HUMAN);
		this.getMoveListeners().add(this.computerPlayer);
		this.setAllowedPlayer(this.computerPlayer.HUMAN);

		this.computerLevels.addItem("VERY Beginner");
		this.computerLevels.addItem("Beginner");
		this.computerLevels.addItem("Intermediat (very slow)");

		this.computerLevels.addChangeHandler(new ChangeHandler() {

			@Override
			public void onChange(final ChangeEvent event) {
				if (PlayWithComputerChessUI.this.computerLevels
						.getSelectedIndex() >= 0) {
					PlayWithComputerChessUI.this.computerPlayer
							.setLevel(PlayWithComputerChessUI.this.computerLevels
									.getSelectedIndex() + 1);
				}
			}
		});

		this.computerLevels.setSelectedIndex(1);

		this.addPreferenceField("Computer level", this.computerLevels);
	}
}
